package it.valeandre.gollometro.view;

import it.valeandre.gollometro.c2dm.R;

import java.io.InputStream;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Movie;
import android.view.View;

public class MYGIFView extends View{

	Movie movie,movie1;
	InputStream is=null,is1=null;
	long moviestart;
	 long mMoviestart;
	
	
	public MYGIFView(Context context) {
		super(context);
		
		is=context.getResources().openRawResource(R.raw.earth);		 
		movie = Movie.decodeStream(is);
	
	} 
	

	@Override
	protected void onDraw(Canvas canvas) {

		canvas.drawColor(Color.WHITE);
		 super.onDraw(canvas);
		 long now = android.os.SystemClock.uptimeMillis();
//		System.out.println("now=" + now);
		if (moviestart == 0) { // first time
		 moviestart = now;    

		}
//		 System.out.println("\tmoviestart=" + moviestart);
		 int relTime = (int) ((now - moviestart) % movie.duration());
//		 System.out.println("time=" + relTime + "\treltime=" + movie.duration());
		 movie.setTime(relTime);
		 movie.draw(canvas, 0, 0);
		 this.invalidate();
	}
	

}
